<script setup lang="ts">
// 监控看板-我的监控
import {message} from "ant-design-vue";
import {getCurrentInstance} from "vue";
import BaseApp from "~/contentScripts/views/sycm/baseApp.vue";
import BrandModal from "~/contentScripts/views/sycm/market_monitor/my_monitor/brandModal.vue";
import ItemModal from "~/contentScripts/views/sycm/market_monitor/my_monitor/itemModal.vue";
import ShopModal from "~/contentScripts/views/sycm/market_monitor/my_monitor/shopModal.vue";
import User from "~/contentScripts/views/tao/list/components/user.vue";
import {isLogin} from "~/logic";
import SYCM from "~/utils/ali/sycm";

const shopVisible = ref(false);
const itemVisible = ref(false);
const brandVisible = ref(false);
const loginVisible = ref(false);
const dataSource = ref<any[]>([]);
const __option = getCurrentInstance()?.appContext.provides.option;
const handle = async () => {
  if (isLogin({
    emit: () => {
      loginVisible.value = true;
    }
  }, __option)) {
    document.querySelector(".mc-marketMonitor .oui-card-header-item.oui-card-header-item-pull-left .oui-tab-switch-item.oui-tab-switch-item-active")?.click();
    const activeProps: any = await SYCM.getInternalFiberData('.mc-marketMonitor div.oui-card-header-wrapper > div.oui-card-header > div.oui-card-header-item.oui-card-header-item-pull-left', 'alternate.memoizedProps.children[0].props');
    if (activeProps == null) {
      message.error('获取数据失败，请刷新后重试！');
      return;
    }
    let currTab = {
      key: activeProps.activeKey,
      name: activeProps.data.find((item: any) => {
        return item.value == activeProps.activeKey
      }).text,
    };
    if (currTab.key == 'shop') {
      shopVisible.value = true;
    } else if (currTab.key == 'item') {
      itemVisible.value = true;
    } else if (currTab.key == 'brand') {
      brandVisible.value = true;
    }
  }
}
</script>

<template>
  <base-app>
    <a-button-group>
      <user @login="loginVisible=true" :style="{
        marginRight: '0'
      }"
      />
      <!--      <a-button type="primary" size="small" @click="handle2">指数换算</a-button>-->
      <a-button type="primary" size="small" @click="handle">一键转化</a-button>
    </a-button-group>
    <shop-modal v-model:visible="shopVisible"/>
    <item-modal v-model:visible="itemVisible"/>
    <brand-modal v-model:visible="brandVisible"/>
    <user-login-modal v-model:visible="loginVisible" @close="loginVisible=false"/>
  </base-app>
</template>

<style scoped>

</style>
